<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();

/*************************************************************************
	Processing of received parameters
*************************************************************************/
if(!isset($arParams["CACHE_TIME"]))
	$arParams["CACHE_TIME"] = 3600;

$arParams["IBLOCK_TYPE"] = trim($arParams["IBLOCK_TYPE"]);
$arParams["IBLOCK_ID"] = intval($arParams["IBLOCK_ID"]);
$arParams["COUNT"] = intval($arParams["COUNT"]);

if($this->StartResultCache(false, $USER->GetGroups()))
{
	if(!CModule::IncludeModule("iblock"))
	{
		$this->AbortResultCache();
		ShowError("Модуль Информационных блоков не найден");
		return;

	}
	
	$arResult["ITEMS"]=array();
	
	$items = CIBlockElement::GetList(
		Array("ACTIVE_FROM"=>DESC),
		Array("ACTIVE"=>"Y", "DATE_ACTIVE"=>"Y", "IBLOCK_ID"=>$arParams["IBLOCK_ID"]),
		false,
		Array("nTopCount"=>$arParams["COUNT"]),
		Array("ID", "NAME", "ACTIVE_FROM", "DETAIL_PAGE_URL", "PREVIEW_TEXT")
	); 
	while ($item = $items->GetNext())
	{
		$navstr = "";
		$navs = CIBlockSection::GetNavChain($arParams["IBLOCK_ID"], $item["IBLOCK_SECTION_ID"]);
		$n = 0;
		while ( $nav = $navs->GetNext() )
		{
			if ( $n++ )
				$navstr .= " / ";
			$navstr .= $nav["NAME"];	
		}
		$item["NAVSTR"] = $navstr;
		$item["NAVURL"] = $nav["SECTION_PAGE_URL"];
		$arResult["ITEMS"][] = $item;
	}

	$this->IncludeComponentTemplate();
}
?>
